#!/usr/bin/env python
import sys, os
CurrDir = os.getcwd()
sys.path.append(CurrDir + '/lib')
import state
import aws
import functions
from ttemplate import TTemplate

class myState(state.State):
    def __init__(self):
        state.State.__init__(self)
        self.aws = aws.AWS()

valid_actions = [
    'default',
    'debug',
    'success',
    'upload',
    'list',
    'delete'
    ]
    
state = myState()

state.action = state.form.getvalue('action','default')
state.action = state.action.strip('/')

if state.action not in valid_actions:
    print "Content-type: text/html"
    print "Location: %s" % state.request_base_url
    print "Status: 301"
    print
    print "Invalid request. Click <a href='%s'>here.</a>" % state.request_base_url
    exit()
    state.action = 'default'

func = getattr(functions, state.action, None)
if func:
    func(state)
else: 
    print "Content-type: text/html\n\n"
    print "failed to execute %s, action %s" % (func, state.action)




